#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int Fibonacci(int arr[])
{
	arr[0] = 0;
	arr[1] = 1;
	int i = 0;
	int j = 2;
	while (arr[j-1]+arr[j-2]<=1000000)
	{
		arr[j] = arr[j - 2] + arr[j - 1];
		j++;
	}
	return j;
}

int Find_Step(int arr[], int num, int NUM)
{
	int i = 0;
	int sub1 = 0;
	int sub2 = 0;
	for (i = 0; i < NUM-1; i++)
	{
		if (num >= arr[i] && num <= arr[i + 1])
		{
			sub1 = num - arr[i];
			sub2 = arr[i + 1] - num;
			if (sub1 >= sub2)
			{
				return sub2;
			}
			else
			{
				return sub1;
			}
		}
		else if (num >= arr[NUM - 1])
		{
			int ret = num - arr[NUM - 1];
			return ret;
		}
	}
}
int main()
{ 
	int arr[1000] = { 0 };
	int NUM = Fibonacci(arr);
	int num = 0;
	scanf("%d", &num);
	int ret = Find_Step(arr, num, NUM);
	printf("%d", ret);
	return 0;
}